export default {
  async invoke(options) {
    const token = uni.getStorageSync('uni_id_token')
    const tokenExpired = uni.getStorageSync('uni_id_token_expired')
    
    if (tokenExpired && tokenExpired < Date.now()) {
      uni.removeStorageSync('uni_id_token')
      uni.removeStorageSync('uni_id_token_expired') 
      token = null
    }
    
    const needLoginPages = [
      '/pages/mine/vip',
      '/pages/mine/follow',
      '/pages/mine/history',
      '/uni_modules/uni-id-pages/pages/userinfo/userinfo'
    ]
    
    const currentPage = options.url.split('?')[0]
    
    if (needLoginPages.includes(currentPage) && !token) {
      uni.setStorageSync('redirect_page', options.url)
      
      uni.navigateTo({
        url: '/uni_modules/uni-id-pages/pages/login/login-withoutpwd'
      })
      return false
    }
    
    return true
  }
} 